<template>
  <div>
    <el-dialog title="修改退款金额" :visible.sync="visible" :before-close="closeDialog" :close-on-click-modal="clickModalClose" :width="dialogWidth">
      <el-form ref="form" :model="form" label-position="top">
        <el-form-item
          label="退款金额"
          prop="money"
          :rules="[
            { required: true, message: '请输入退款金额', trigger: 'blur' },
            ]"
          style="margin-bottom: 0"
        >
          <!-- <el-input v-model.number="form.money" autocomplete="off" clearable /> -->
          <el-input-number v-model="form.money" :precision="2" :step="0.1" :min="0.01" :max="details ? details.onemoney : 0"></el-input-number>
          <p style="line-height: 1;color: #999">该笔订单最高可退金额为：￥{{ details ? details.onemoney : '0.00' }}元。</p>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { setRefundMoney } from '@/api/aftermarket'
import dialogMixin from '@/components/Mixins/dialog'
export default {
  mixins: [dialogMixin],
  props: {
    visible: { type: Boolean, default: false },
    aftermarketid: { type: String, default: null },
    details: { type: Object }
  },
  data(vm) {
    return {
      form: {
        money: this.details ? this.details.onemoney : '0.00',
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          const res = await setRefundMoney({
            money: this.form.money,
            aftermarketid: this.aftermarketid,
          })
          this.closeDialog()
          this.$notify({
            title: '提示',
            type: res.code === 1001 ? 'success' : 'error',
            message: res.msg || '退款金额修改成功',
            position: 'bottom-right'
          })
        }
      })
    },
    closeDialog() {
      this.$refs.form.resetFields()
      this.$emit('update:visible', false)
      this.$emit('getData')
    }
  }
}
</script>
